<template>
  <div>
    <div class="box_header">
      <div v-for="(item, index) in list" :key="index" @click="select(index)">
        <p>{{ item }}</p>
        <span :class="active === index ? 'box_header_select' : ''"></span>
      </div>
    </div>
    <ul class="box_pro">
      <li v-for="(item, index) in proList" :key="index" @click="toProDetail(item.proid)">
        <img :src="item.pro_pic" alt="">
        <div class="box_pro_content">
          <h5>{{item.pro_introduce}}</h5>
          <div>
            <span>{{item.clinic_name}}</span>
            <span>{{item.distance + 'km'}}</span>
          </div>
          <p>
            <span>{{item.pro_discounts}}</span>
          </p>
          <div>
            <span>{{'￥' + item.pro_price}}</span>
            <span>{{item.subscribe + '人预约'}}</span>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { getWelfareList } from '../../api'
import Vue from 'vue'
import { Toast } from 'vant'
Vue.use(Toast)
export default {
  data () {
    return {
      active: 0,
      list: ['智能排序', '距离', '价格排序'],
      proList: [],
      myCouponsList: []
    }
  },
  mounted () {
    this.getAllProduct()
  },
  methods: {
    select (index) {
      this.active = index
      if (index === 1) {
        this.proList.sort((a, b) => {
          return a.distance - b.distance
        })
        return
      }
      if (index === 2) {
        this.proList.sort((a, b) => {
          return a.pro_price - b.pro_price
        })
        return
      }
      if (index === 0) {
        this.getAllProduct()
      }
    },
    toProDetail (proId) {
      const proid = proId.toString()
      this.$router.push({ path: '/welfareDetail', query: { proid } })
    },
    getAllProduct () {
      getWelfareList().then(res => {
        this.proList = res.data.data
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.box_header {
  height: 0.45rem;
  width: 100%;
  padding: 0 0.15rem;
  line-height: 0.45rem;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #f6f6f6;
  div {
    position: relative;
    p {
      padding: 0 0.03rem;
      text-align: center;
      font-size: 0.16rem;
      color: #464646;
    }
    .box_header_select {
      display: block;
      width: 100%;
      height: 0.1rem;
      background: #ffe7e8;
      border-radius: 0.03rem;
      position: absolute;
      bottom: 0.14rem;
      z-index: -1;
    }
  }
}
.box_pro {
  width: 100%;
  height: 1.32rem;
  li {
    padding: 0.18rem 0.15rem;
    width: 100%;
    height: 1.32rem;
    border-bottom: 1px solid #f6f6f6;
    img {
      width: 0.92rem;
      height: 0.96rem;
      margin-right: 0.18rem;
      float: left;
    }
    .box_pro_content {
      width: 2.35rem;
      height: 0.96rem;
      float: left;
      h5 {
        width: 100%;
        height: 0.36rem;
        line-height: 0.18rem;
        font-size: 0.14rem;
        font-weight: normal;
        color: #464646;
        margin-bottom: 0.06rem;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      div:nth-of-type(1) {
        width: 100%;
        height: 0.14rem;
        margin-bottom: 0.04rem;
        line-height: 0.14rem;
        span {
          font-size: 0.12rem;
          color: #808080;
          height: 0.12rem;
        }
        span:nth-of-type(1) {
          float: left;
          max-width: 1.6rem;
          overflow: hidden;
          text-overflow:ellipsis;
          white-space: nowrap;
        }
        span:nth-of-type(2) {
          float: right;
        }
      }
      p {
        width: 100%;
        height: 0.12rem;
        margin-bottom: 0.1rem;
        span {
          display: inline-block;
          padding: 0 0.03rem;
          line-height: 0.12rem;
          font-size: 0.08rem;
          color: #FF5959;
          border: 1px solid #FF5959;
          box-sizing: border-box;
          border-radius: 0.03rem;
        }
      }
      div:nth-of-type(2) {
        width: 100%;
        height: 0.16rem;
        line-height: 0.16rem;
        span:nth-of-type(1) {
          float: left;
          color: #FF5959;
          font-size: 0.16rem;
        }
        span:nth-of-type(2) {
          float: right;
          color: #808080;
          font-size: 0.12rem;
        }
      }
    }
  }
}
</style>
